package edu.hnu.cloudflightserver.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import edu.hnu.cloudflight.android.domain.FlightWarnModel;
import edu.hnu.cloudflight.android.domain.ServerRequest;
import edu.hnu.cloudflightserver.server.FlightWarnServer;
import edu.hnu.cloudflightserver.util.LogUtil;


@WebServlet(name="FlightWarnServer",urlPatterns={"/flightwarnserver"})

public class FlightWarnServerServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7358886484955021070L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String token = req.getParameter("token");
		String type = req.getParameter("type");
		String flightNum = req.getParameter("flightnum");
		LogUtil.debug(getClass(), "FlightWarnServer", token+"   "+type+"    "+flightNum);
		// 后台服务处理.....
		
		FlightWarnModel fwm = new FlightWarnModel();
		fwm.token=token;
		fwm.flightNum=flightNum;
	    FlightWarnServer.addTask(fwm);
		
		ServerRequest sr = new ServerRequest();
		sr.resultcode="200";
		sr.reason="success";
		String result = JSON.toJSONString(sr);
		PrintWriter pw = resp.getWriter();
		pw.println(result);
		pw.flush();
		pw.close();

	}

}
